﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace GraphicsEditor
{
    static class Resizer
    {
        //Resizes the image via Percent.
        public static Bitmap PercentResize(Bitmap img, float percentChange, int choice)
        {
            //The new bitmap is the current image's size (width and height) multiplied by the percent change
            Bitmap resizedBitmap = new Bitmap((int)(img.Width * percentChange), (int)(img.Height * percentChange));

            //Create a new graphics object from the resizedBitmap.
            Graphics graphicsObject = Graphics.FromImage(resizedBitmap);

            //Set the mode for Interpolation and the type base upon what the user has choosen in the combo box.
            if(choice == 0)
                graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            else if(choice == 1)
                graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            else if(choice == 2)
                graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            else if(choice == 3)
                graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bicubic;
            else if(choice == 4)
                graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            else if(choice == 5)
                graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            else if(choice == 6)
                graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
            else
                graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            
            //Draw 
            graphicsObject.DrawImage(img, 0, 0, (int)(img.Width * percentChange), (int)(img.Height * percentChange));
            
            //Garbage removal
            graphicsObject.Dispose();

            return resizedBitmap;
        }

        //Relative works by adding (or removing) to the pixels an image already has.
        public static Bitmap Relative(Bitmap img, int width, int height)
        {
            //The new bitmap is the current image's size (width and height) multiplied by the percent change
            Bitmap resizedBitmap = new Bitmap((int)(img.Width + width), (int)(img.Height + height));

            //Create a new graphics object from the resizedBitmap.
            Graphics graphicsObject = Graphics.FromImage(resizedBitmap);

            //Set the mode for Interpolation and the type.
            graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            //Draw 
            graphicsObject.DrawImage(img, 0, 0, (int)(img.Width + width), (int)(img.Height + height));

            //Garbage removal
            graphicsObject.Dispose();

            return resizedBitmap;
        }

        //Set the pixels for the Width and Height of an image.
        public static Bitmap Set(Bitmap img, int width, int height)
        {
            //The new bitmap is the current image's size (width and height) multiplied by the percent change
            Bitmap resizedBitmap = new Bitmap((int)(width), (int)(height));

            //Create a new graphics object from the resizedBitmap.
            Graphics graphicsObject = Graphics.FromImage(resizedBitmap);

            //Set the mode for Interpolation and the type.
            graphicsObject.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            //Draw 
            graphicsObject.DrawImage(img, 0, 0, (int)(width), (int)(height));

            //Garbage removal
            graphicsObject.Dispose();

            return resizedBitmap;
        }
    }
}
